package org.jeecg;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.service.ISysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 单体启动类
 * 报错提醒: 未集成mongo报错，可以打开启动类上面的注释 exclude={MongoAutoConfiguration.class}
 */
@Slf4j
@EnableAsync
@SpringBootApplication
@EnableScheduling //定时任务在启动类注解
//@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})
public class wtest extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(JeecgSystemApplication.class);
    }
    @Component("A")
    @Data
    class A {
        @Autowired
         ISysPermissionService sysPermissionService;
    }

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(JeecgSystemApplication.class, args);
        A a = (A) application.getBean("A");
        ISysPermissionService sysPermissionService = a.getSysPermissionService();
        QueryWrapper<SysPermission> sysPermissionQueryWrapper = new QueryWrapper<SysPermission>();
        sysPermissionQueryWrapper.like("name","管理");
        sysPermissionQueryWrapper.like("url","mes");
        sysPermissionQueryWrapper.ge("create_time","2023-06-29 00:00:00");
        for (SysPermission sysPermission : sysPermissionService.list(sysPermissionQueryWrapper)) {
//            sysPermission.setUrl(sysPermission.getUrl()+"/look");
//            sysPermission.setComponent(sysPermission.getComponent().replace("mes/","mes_per/"));
//            sysPermission.setId(null);
//            sysPermissionService.addPermission(sysPermission);
            sysPermission.setName(sysPermission.getName().replace("管理","查看"));
            sysPermissionService.updateById(sysPermission);

            System.out.println(sysPermission);
        }
        while (true){
            System.out.println("just_wait");
        }
    }

}